package com.example.disk.component;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * TODO
 *
 * @author lpc
 * @version 1.0.0
 * @since 2020-07-16 21:03
 */

@Component
@Slf4j
public class LoginInterceptor  implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getSession() == null ||
                request.getSession().getAttribute("login") == null ||
                !(boolean)request.getSession().getAttribute("login")) {
            response.setStatus(403);
            log.info("验证没有通过");
            return false;
        }
        return true;
    }
}
